//
//  CAShopCartBottomView.m
//  LNH
//
//  Created by twentylx on 2018/2/17.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAShopCartBottomView.h"

@implementation CAShopCartBottomView

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params {
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView {
    
}

/**
 初始化视图
 */
- (void)lm_createViewForView {
    [self setNeedsUpdateConstraints];
    
    [self addSubview:self.bottomView];
    [self.bottomView addSubview:self.selectAllButton];
    [self.bottomView addSubview:self.totalLabel];
    [self.bottomView addSubview:self.totalPriceLabel];
    [self.bottomView addSubview:self.submitButton];
}

- (void)updateConstraints {
    [super updateConstraints];
    
    [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self);
        make.height.mas_equalTo(44);
    }];
    
    [_selectAllButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bottomView).offset(20);
        make.centerY.equalTo(self.bottomView);
        make.size.mas_equalTo(CGSizeMake(60, 20));
    }];
    
    [_totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.totalPriceLabel.mas_left);
        make.centerY.equalTo(self.bottomView);
    }];
    
    [_totalPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.submitButton.mas_left).offset(-20);
        make.centerY.equalTo(self.bottomView);
    }];
    
    [_submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bottomView);
        make.top.and.bottom.equalTo(self.bottomView);
        make.width.mas_equalTo(100);
    }];
    
}

#pragma mark get & set
- (UIView *)bottomView {
    if (!_bottomView) {
        _bottomView = [UIView new];
    }
    return _bottomView;
}

- (UIButton *)selectAllButton {
    if (!_selectAllButton) {
        _selectAllButton = [UIButton new];
        [_selectAllButton setImage:LMImageNamed(@"shopcart_selectNormal") forState:UIControlStateNormal];
        [_selectAllButton setImage:LMImageNamed(@"shopcart_select") forState:UIControlStateSelected];
        [_selectAllButton setTitle:@"全选" forState:UIControlStateNormal];
        _selectAllButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [_selectAllButton setTitleColor:RGBCOLOR(35, 24, 21) forState:UIControlStateNormal];
        _selectAllButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0,0);
        _selectAllButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    return _selectAllButton;
}

-(UILabel *)totalLabel {
    if (!_totalLabel) {
        _totalLabel = [UILabel new];
        _totalLabel.text = @"合计：";
        _totalLabel.font = [UIFont systemFontOfSize:16];
        _totalLabel.textColor = RGBCOLOR(35, 24, 21);
    }
    return _totalLabel;
}

-(UILabel *)totalPriceLabel {
    if (!_totalPriceLabel) {
        _totalPriceLabel = [UILabel new];
        _totalPriceLabel.text = @"0.00";
        _totalPriceLabel.font = [UIFont systemFontOfSize:16];
        _totalPriceLabel.textColor = RGBCOLOR(233, 85, 19);
    }
    return _totalPriceLabel;
}

- (UIButton *)submitButton {
    if (!_submitButton) {
        _submitButton = [UIButton new];
        [_submitButton setTitle:@"结算" forState:UIControlStateNormal];
        _submitButton.titleLabel.font = [UIFont systemFontOfSize:20];
        [_submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _submitButton.backgroundColor = RGBCOLOR(233, 85, 19);
    }
    return _submitButton;
}


@end
